package com.javacv.plus.core.config;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 处理器配置基类
 */
@Data
public class ProcessorConfig {

    /**
     * 输入文件路径
     */
    private String inputPath;

    /**
     * 输出文件路径
     */
    private String outputPath;

    /**
     * 是否启用调试模式
     */
    private boolean debug = false;

    /**
     * 线程池大小
     */
    private int threadPoolSize = Runtime.getRuntime().availableProcessors();

    /**
     * 超时时间（毫秒）
     */
    private long timeout = 30000;

    /**
     * 扩展配置
     */
    private Map<String, Object> properties = new HashMap<>();

    /**
     * 设置扩展属性
     */
    public ProcessorConfig setProperty(String key, Object value) {
        properties.put(key, value);
        return this;
    }

    /**
     * 获取扩展属性
     */
    @SuppressWarnings("unchecked")
    public <T> T getProperty(String key) {
        return (T) properties.get(key);
    }

    /**
     * 获取扩展属性，如果不存在则返回默认值
     */
    @SuppressWarnings("unchecked")
    public <T> T getProperty(String key, T defaultValue) {
        return (T) properties.getOrDefault(key, defaultValue);
    }

    /**
     * 检查是否包含属性
     */
    public boolean hasProperty(String key) {
        return properties.containsKey(key);
    }

    /**
     * 创建配置构建器
     */
    public static ConfigBuilder builder() {
        return new ConfigBuilder();
    }

    /**
     * 配置构建器
     */
    public static class ConfigBuilder {
        private ProcessorConfig config = new ProcessorConfig();

        public ConfigBuilder input(String inputPath) {
            config.setInputPath(inputPath);
            return this;
        }

        public ConfigBuilder output(String outputPath) {
            config.setOutputPath(outputPath);
            return this;
        }

        public ConfigBuilder debug(boolean debug) {
            config.setDebug(debug);
            return this;
        }

        public ConfigBuilder threadPoolSize(int size) {
            config.setThreadPoolSize(size);
            return this;
        }

        public ConfigBuilder timeout(long timeout) {
            config.setTimeout(timeout);
            return this;
        }

        public ConfigBuilder property(String key, Object value) {
            config.setProperty(key, value);
            return this;
        }

        public ProcessorConfig build() {
            return config;
        }
    }
} 